<template>
	<view class="content">
		<view class="row"><text class="title">账户余额：</text>
		<text style="color: #FF0000;">{{cardInfo.money}}</text> 元</view>
		<view class="row">
			<text class="title">充值订单：</text>{{cardInfo.order_no}}
			</view>
		<view class="row">
			<text class="title">充值类型：</text>{{cardInfo.card_name}}
		</view>
		<view class="row"><text class="title">充值金额：</text><text style="color: #FF0000;">{{cardInfo.price}}</text> 元</view>
		<view class="row">
			<text class="title">支付方式：</text>
			<image :src="imagePath" style="width: 203rpx; height: 63rpx;"></image>
		</view>
		<view class="row" style="font-size: 28rpx; justify-content:center;color: #9B9EA3; align-items: center;text-align: center;">
			如果余额充足，会自动使用余额充值，付款后可到充值记录中查看是否到账，若付款后10分钟未到账，请联系客服
		</view>
		<view style="margin-top: 50rpx;">
			<button type="primary" :disabled="!cardInfo.card_type" @click="createOrder()">确认充值</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buytype:"",
				typeName:"",
				order_no:"",
				cardInfo:{},
				payType:"ali",
				imagePath:require("static/wx.png"),
				loaded:false
			}
		},
		onLoad(data) {
			this.buytype = data.type;
			this.payType = data.payt;
			this.order_no = data.order_no ? data.order_no : "";
			this.loadCardInfo(this.buytype);
			this.imagePath = require("static/"+data.payt+".png");
			setTimeout(()=>{
				this.loaded = true;
			},2000);
		},
		onShow() {
			
			if(this.loaded){
				uni.showModal({
					title:'提示',
					content:"是否完成充值？",
					success(res) {
						if (res.confirm) {
							uni.switchTab({
								url:"../my/my"
							});
						}
					}
				});
			}
		},
		methods: {
			loadCardInfo(type){
				uni.showLoading({
					title:"加载中..."
				});
				this.request.get({
					url:"index/member/cardinfo?type="+type+"&payt="+this.payType+"&order_no="+this.order_no,
					success:(res)=>{
						uni.hideLoading();
						if(res.data.code != 1){
							uni.showToast({
								icon:"none",
								title:res.data.msg ?  res.data.msg : "请求错误"
							});
							return;
						}
						this.cardInfo = res.data.data;
					}
				});
			},
			createOrder(){
				var that = this;
				uni.showLoading({
					title:"正在提交..."
				});
				this.request.post({
					url:"index/member/recharge",
					data:{
						order_no:this.cardInfo.order_no
					},
					success:(res)=>{
						uni.hideLoading();
						if(res.data.code != 1){
							uni.showToast({
								icon:"none",
								title:res.data.msg ?  res.data.msg : "请求错误"
							});
							return;
						}
						if(!res.data.data){
							uni.showToast({
								icon:"none",
								title:res.data.msg ?  res.data.msg : "充值成功"
							});
							uni.switchTab({
								url:"../my/my"
							});
							return;
						}
						
						uni.navigateTo({
							url:"recharge?order_no="+that.cardInfo.order_no+"&url="+res.data.data
						});
						//console.log(res);
					}
				});
			},
			radioChange(evt){
				this.payType = evt.target.value;
			}
		}
	}
</script>

<style>
.content{
	padding: 40rpx;
	color: #333333;
}
.row{
	padding: 20rpx 0rpx;
	display: flex;
	align-items: center;
	font-size: 16px;
}
.title{
	font-weight: bold;
}
</style>
